package com.taskcollection.servlet;

import com.alibaba.fastjson.JSONObject;
import com.taskcollection.bean.TeacherBean;
import com.taskcollection.service.TeacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2016/7/28 0028.
 */
@WebServlet(name = "TeacherServlet")
public class TeacherServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String flag = request.getParameter("flag");
        TeacherService ts = new TeacherService();
        JSONObject json = new JSONObject();
        if("getAll".equals(flag)){
            List<TeacherBean> tbList = ts.getAll();
            json.put("getAll",tbList);
            System.out.println(json.toJSONString());
        }
        response.getWriter().print(json.toJSONString());
    }
}
